package br.com.decsoft.lv.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import br.com.decsoft.lv.jdbc.ConnectionFactory;

public class ClienteDAO {

	private Connection conn = null;
	private Statement stm = null;

	public ClienteDAO() throws SQLException {
		this.conn = ConnectionFactory.getConnection();
	}

	public String validarSenha(String cnpj_cpf, String senha) throws SQLException {
		String result = "";
		System.out.println("CNPJ/CPF recebido: "+cnpj_cpf);
		try {
			stm = conn.createStatement();
			ResultSet rs = stm.executeQuery("select CLIEA13ID from CLIENTE where " +
						   "((CLIEA11CPF = '"+cnpj_cpf+"') or (CLIEA14CGC = '"+cnpj_cpf+"')) and " +
						   " (CLIEA8SENHAINTERNET = '"+senha+"')");
			rs.next();

			result = rs.getString("CLIEA13ID");
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			stm.close();
			conn.close();
		}
		
		return result;
	}	
}